package oocl.ita.eordering.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import oocl.ita.eordering.dao.ClientDao;
import oocl.ita.eordering.po.Client;

@Repository("cDao")
public class ClientDaoImpl implements ClientDao {
	@PersistenceContext(name="un")//auwire 的子类
	private EntityManager em;
	@Override
//	@Transactional
	public int addClient(Client c) {
		int rs=0;
		
		
		em.persist(c);
		
		
		return c.getcId();
	}

	@Override
	public Client findClient(String tel, String psd) {
		
		String jpql="select c from Client c where c.cTel=:cTel and c.cPassword=:cPassword";
		List<Client> ls=em.createQuery(jpql)
				.setParameter("cTel", tel)
				.setParameter("cPassword", psd)
				.getResultList();
		if(ls.isEmpty()) return null;
		else return ls.get(0);
		
	}

	@Override
	public int updateClient(Client client) {
		// TODO Auto-generated method stub
		return 0;
	}
}
